<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CYayasan extends DR_Controller {

	function __Construct()
	{
		parent::__Construct();
		$this->load->model("yayasan");
		$this->load->library("pagination");

		$this->only_admin("admin/main/login");	
	}
	
	private function redirect_if_null($id=null,$url=null)
	{
		if($id==null)
		{
			if($url!=null)
			{
				redirect($url);
			}
			
			redirect("admin/cyayasan");
		}
	}
	
	
	public function add()
	{
	}
	
	function detail($id=null)
	{
		$this->redirect_if_null($id);
		
		$data["yayasan"] = $this->yayasan->get_by_id($id);
		$data["location"] = $this->yayasan->lokasi->get_by_yayasan_id($id);
		$data["layanan"] = $this->yayasan->layanan->get_by_yayasan_id($id);
		$data["foto"] = $this->yayasan->photos->get_by_yayasan_id($id);
		$data["youtube"] = $this->yayasan->youtube->get_by_yayasan_id($id);
		$data["laporan_keuangan"] = $this->yayasan->laporan_keuangan->get_by_yayasan_id($id);
		
		$this->set_view("admin/header",'admin/yayasan/detail',$data);
	}
	
	function index($offset=null,$field=null,$value=null)
	{
		$filter=null;
		if($field!=null & $value!=null){
			$offset = $this->uri->segment(7); 
			$config['uri_segment']=7;					
			$filter = "$field like '%$value%'";
			$config['base_url'] = site_url("/admin/cyayasan/index/0/$field/$value");
			$config['total_rows'] = $this->yayasan->get_count($filter);			
			
			$data["filtered"] = true;
			
			//download filtered
			$this->session->set_flashdata("filter",$filter);			
			
		}
		else
		{
			$data["filtered"] = false;
			
			$offset = $this->uri->segment(4); 
			$config['uri_segment']=4;					
			$filter = array();
			$config['base_url'] = site_url('/admin/cyayasan/index/');
			$config['total_rows'] = $this->yayasan->get_count($filter);			
		}
				
        $config['per_page'] = 20;
        $this->pagination->initialize($config);
        $paginator=$this->pagination->create_links();
		
		$data["offset"] = $offset;
		$this->yayasan->set_default_order(array("nama_yayasan"=>"asc"));		
		$data['result'] = $this->yayasan->get_paged($config['per_page'],$offset,$filter);
		$data['total_page'] = $paginator;		
		$data["config"] = $config;
		
		//sekarang gunakan set view. agar content dirender didalam container
		$this->set_view("admin/header",'admin/yayasan/list',$data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */